<template>
  <div>
    <Header></Header>
    <Banner></Banner>
    <div class="main">
      <div class="main-left">
        <li  @click="$router.push('/wz')" v-if="this.author == 2">
          <i class="iconfont icon-all-wenzhang"></i>
          我的文章
        </li>
        <li  @click="$router.push('/sc')">
          <i class="iconfont icon-all-xiangqu"></i>
          我的关注
        </li>
        <li  @click="$router.push('/wd')">
          <i class="iconfont icon-all-wendabangzhu"></i>
          我的问答
        </li>
        <li  @click="$router.push('/pl')">
          <i class="iconfont icon-all-pinglun"></i>
          我的评论
        </li>
        <li class="active"  @click="$router.push('/dy')">
          <i class="iconfont icon-all-yonghuming"></i>
          我的订阅
        </li>
        <li  @click="$router.push('/ds')">
          <i class="iconfont icon-all-qian"></i>
          我的打赏
        </li>
        <li  @click="$router.push('/tz')">
          <i class="iconfont icon-all-tongzhi"></i>
          通知中心
        </li>
        <li  @click="$router.push('/ll')">
          <i class="iconfont icon-all-liulan"></i>
          浏览记录
        </li>
        <li  @click="$router.push('/sz')">
          <i class="iconfont icon-all-icon_setting"></i>
          资料设置
        </li>
      </div>
      <div class="main-right">
        <div class="nav">
          <span v-bind:class="{ active1: isActive1}">我订阅的专栏（{{totalCount}}）</span>
        </div>
        <div v-if="this.speciaList.length==0" style="text-align: center; font-size:16px;padding-top:10px;">您还没有订阅作家</div>
        <div class="content" v-if="this.speciaList.length>0">
          <div class="content-item"  v-for="(item,index) in speciaList" :key="index" >
            <div class="upper">
              <img :src="item.avatar" alt>
              <h4>{{item.nickname}}</h4>
              <div  class="tip" >
                <span v-for="(idx,index) in speciaList[index].category_list" :key="index"> {{idx.title}}</span>
              </div>
              <!-- <div  v-if="!this.speciaList[index].category_list"> 
                  暂无标签
              </div> -->
            </div>
            <div class="down">
              <span @click="qx(item)">取消订阅</span>
            </div>
          </div>
          <div class="more" v-if="totalCount>9">
            <button @click="getMore">加载更多</button>
          </div>
        </div>
      </div>
    </div>
    <Footer></Footer>
  </div>
</template>

<script>
import Header from "@/common/Header/Header";
import Footer from "@/common/Footer/Footer";
import Banner from "@/common/Banner/Banner";
import qs from "qs";
export default {
  name: "dy",
  data() {
    return {
      isActive1: true,
      speciaIndex:9,
      speciaList:[],
      totalCount:'',
      author:'',
    };
  },
  methods: {
    //获取订阅的专家
    getAllSpecia(){
      this.$axios
        .get(
          "api/App/User/Set/web_user_attention_question?member_id=" +
            this.getCookie("member_id") +
            "&p=1&type=4&limit=" +
            this.speciaIndex +
            "&to_member_id=" +
            this.getCookie("member_id"),
        )
        .then(res => {
          console.log(res)
          this.speciaList = res.data.data.list;
          this.totalCount= res.data.data.count;
        });
    },
    //取消订阅
    qx(item){
      console.log(item)
      // return;
      let param = {
        source_id: item.source_id,
        member_id: this.getCookie("member_id"),
        type: 4
      };
      this.$axios
        .post("/api/App/User/Question/web_cancel_attentions", qs.stringify(param), {
          headers: { "Content-Type": "application/x-www-form-urlencoded" }
        })
        .then(res => {
          item.is_attentions =0;
          this.getAllSpecia();
        });
    },
    //加载更多订阅的专家
    getMore(){
      this.speciaIndex = this.speciaIndex + 9;
      this.$axios
        .get(
          "api/App/User/Set/web_user_attention_question?member_id=" +
            this.getCookie("member_id") +
            "&p=1&type=4&limit=" +
            this.speciaIndex +
            "&to_member_id=" +
            this.getCookie("member_id"),
        )
        .then(res => {
          console.log(res)
          this.speciaList = res.data.data.list;
          this.totalCount= res.data.data.count;
        });
    }
  
  },
   mounted() {
     this.author =this.getCookie("identity_type") 
   },
  created(){
   this.getAllSpecia();
  },
  components: {
    Header,
    Banner,
    Footer
  }
};
</script>
<style lang="scss" scoped>
.main {
  width: 60%;
  height: auto;
  margin: 0 auto;
  margin-top: 30px;
  margin-bottom: 30px;
  display: flex;
  justify-content: space-between;
  .main-left {
    width: 230px;
    background-color: #fff;
    li {
      padding: 20px;
      list-style: none;
      border-left: 1px solid transparent;
      font-size: 18px;
      cursor: pointer;
    }
    .active {
      background-color: #f2f5fb;
      border-left: 1px solid #5079b7;
      color: #5079b7;
    }
  }
  .main-right {
    text-align: left;
    width: 900px;
    background-color: #fff;
    padding: 20px;
    margin-left: 30px;
    .nav {
      line-height: 1.8;
      border-bottom: 1px solid #5079b7;
      span {
        padding-bottom: 8px;
        display: inline-block;
        margin-right: 10px;
      }
      .active1 {
        color: #5079b7;
        border-bottom: 1px solid #5079b7;
      }
      .money {
        margin-left: 325px;
      }
    }
    .content {
          overflow: auto;
          height: 600px;
      .content-item {
        width: 205px;
        display: inline-block;
        margin-right: 20px;
        margin-top: 40px;
        text-align: center;
        border: 1px solid rgba(0, 0, 0, 0.15);
        border-radius: 5px;
        line-height: 1.8;
        .upper {
          img {
            width: 48px;
            height: 48px;
            border-radius: 100%;
            margin-top: -24px;
          }
          h4 {
            margin-top: 0;
            margin-bottom: 10px;
          }
          .tip {
            font-size: 12px;
            color: #a5aab0;
            display: flex;
            flex-wrap: wrap;
            width: 180px;
            height: 40px;
            margin: 0 auto;
            span{
              padding-left: 10px;
            }
          }
        }
        .down {
          font-size: 12px;
          color: #a5aab0;
          padding: 6px 0 12px;
          overflow: hidden;
          margin-top: 10px;
          span {
            border: 1px solid #5079b7;
            color: #5079b7;
            padding: 0 6px;
            border-radius: 3px;
            cursor: pointer;
          }
        }
      }
      .more{
        width: 100%;
        text-align: center;
        button{        
        border-radius: 10px;
        border: 0;
        outline: none;
        background: linear-gradient(90deg, #00aeff, #3369e7);
        color: #fff;
        box-shadow: 0 2px 6px 0 rgba(51, 105, 231, 0.4);
        margin-top: 20px;
        cursor: pointer;
      }
      }
    }
  }
}
</style>


